package dcc.app;

import java.awt.EventQueue;
import java.util.Locale;

import javax.swing.JOptionPane;

import org.apache.log4j.PropertyConfigurator;

import dcc.mbg.model.User;
import dcc.tools.BeanFactory;
import dcc.tools.Tools;
import dcc.ui.ErrorDialog;
import dcc.ui.LoginWindow;
import dcc.ui.MainWindow;

public class Application {

	private String log4jConfig = "/dcc/resources/config/log4j.properties";
	private String appConfig = "/dcc/resources/config/app.properties";

	private LoginWindow loginWindow;

	public void showMainWindow(User user) {
		loginWindow.close();
		new MainWindow(this, user);
	}

	public Application() {
		try {
			PropertyConfigurator.configure(this.getClass().getResource(
					log4jConfig));
			BeanFactory.build();
			Tools.get().loadProperties(this.appConfig);
			this.loginWindow = new LoginWindow(this);
		} catch (Exception e) {
			e.printStackTrace();
			new ErrorDialog();
		}
	}

	public static void main(String[] args) {
		try {
			JOptionPane.setDefaultLocale(Locale.CHINA);
			// for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
			// {
			// if ("Windows".equals(info.getName())) {
			// UIManager.setLookAndFeel(info.getClassName());
			// break;
			// }
			// }
		} catch (Exception e) {
			e.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				new Application();
			}
		});
	}
}
